#!/usr/bin/env node

const { execSync } = require('child_process')
const path = require('path')
const fs = require('fs')

// 需要安装依赖的目录
const directories = [
  '.',
  './main-app',
  './apps/master-data-app',
  './apps/procurement-app', 
  './apps/operation-app',
  './shared'
]

console.log('📦 开始安装所有依赖...\n')

directories.forEach(dir => {
  const fullPath = path.resolve(__dirname, '..', dir)
  const packageJsonPath = path.join(fullPath, 'package.json')
  
  if (fs.existsSync(packageJsonPath)) {
    console.log(`🔧 安装 ${dir} 的依赖...`)
    
    try {
      execSync('npm install', {
        cwd: fullPath,
        stdio: 'inherit'
      })
      console.log(`✅ ${dir} 依赖安装完成\n`)
    } catch (error) {
      console.error(`❌ ${dir} 依赖安装失败:`, error.message)
    }
  } else {
    console.log(`⚠️  跳过 ${dir} (未找到 package.json)\n`)
  }
})

console.log('🎉 所有依赖安装完成!')
console.log('💡 运行 npm run dev 启动开发环境')